package com.hxkcloud.nurse.views;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import com.hxkcloud.nurse.R;


/**
 *弹出框
 */

public class NoticeDialog extends Dialog{

	private Context mContext;
	private TextView tv_notice_dialog_msg;
	private TextView tv_notice_dialog_cancel;
	private TextView tv_notice_dialog_ok;
	private View tv_notice_dialog_line;
	
	public NoticeDialog(Context context) {
		super(context, R.style.notice_dalog);
		mContext = context;
		init();
	}
	
	private void init() {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		View v = inflater.inflate(R.layout.dialog_notice, null);
		tv_notice_dialog_msg = (TextView) v.findViewById(R.id.tv_notice_dialog_msg);
		tv_notice_dialog_cancel = (TextView) v.findViewById(R.id.tv_notice_dialog_cancel);
		tv_notice_dialog_ok = (TextView) v.findViewById(R.id.tv_notice_dialog_ok);
		tv_notice_dialog_line = v.findViewById(R.id.tv_notice_dialog_line);
		this.setContentView(v);
		this.setCanceledOnTouchOutside(false);

		DisplayMetrics dm = new DisplayMetrics();
		((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(dm);
		LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
		// p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
		p.width = (int) (dm.widthPixels * 0.80); // 宽度设置为屏幕的0.6

		getWindow().setAttributes(p); // 设置生效
	}

	
	/*
	 * msg 设置
	 */
	public void setMsgText(String text) {
		tv_notice_dialog_msg.setVisibility(View.VISIBLE);
		tv_notice_dialog_msg.setText(text);
	}

	public void setMsgText(int text) {
		tv_notice_dialog_msg.setVisibility(View.VISIBLE);
		tv_notice_dialog_msg.setText(text);
	}
	
	public void setMsgTextColor(int color) {
		tv_notice_dialog_msg.setTextColor(color);
	}
	
	public void setMsgTextSize(float textSize) {
		tv_notice_dialog_msg.setTextSize(textSize);
	}
	
	public TextView getMsgText(){
		return tv_notice_dialog_msg;
	}
	
	/*
	 * cancel 设置
	 */
	public void setCancelText(String text) {
		tv_notice_dialog_cancel.setText(text);
	}
	
	public void setCancelTextColor(int color) {
		tv_notice_dialog_cancel.setTextColor(color);
	}
	
	public void setCancelTextSize(float textSize) {
		tv_notice_dialog_cancel.setTextSize(textSize);
	}
	
	public TextView getCancelText() {
		return tv_notice_dialog_cancel;
	}
	
	public void setCancelListener(View.OnClickListener listener) {
		tv_notice_dialog_cancel.setOnClickListener(listener);
	}

	/*
	 * ok 设置
	 */
	public void setOkText(String text) {
		tv_notice_dialog_ok.setText(text);
	}
	
	public void setOkTextColor(int color) {
		tv_notice_dialog_ok.setTextColor(color);
	}
	
	public void setOkTextSize(float textSize) {
		tv_notice_dialog_ok.setTextSize(textSize);
	}
	
	public TextView getOkText() {
		return tv_notice_dialog_ok;
	}
	
	public void setOkListener(View.OnClickListener listener) {
		tv_notice_dialog_ok.setOnClickListener(listener);
	}
	
//	public void setOnlyOneBut() {
//		tv_notice_dialog_cancel.setVisibility(View.GONE);
//		tv_notice_dialog_ok.setBackgroundResource(R.drawable.bg_textview_select_one);
//		tv_notice_dialog_line.setVisibility(View.GONE);
//	}

	
	@Override
	public void show() {
		try {
			if (mContext == null || ((Activity) mContext).isFinishing()) {
				return;
			}
			super.show();
		} catch (Exception e) {
		}
	}

}
